﻿//l_request.hpp
#ifndef L_REQUEST_HPP
#define L_REQUEST_HPP

#include "request.hpp"
#include <iostream>
#include "l_utility.hpp"

namespace http {
    namespace server3 {

        int l_request_get_Slave_ID(lua_State *L);

        static inline void l_set_request(lua_State *L, request* req) {
            lua_getglobal(L,__WEBQUEUE_TABLE); // push table t on stack
            lua_pushlightuserdata(L,req); // push value v on stack
            // stack[-2] = t; stack[-1] = v
            // so t[key] = req
            lua_setfield(L,-2,__WEBQUEUE_REQUEST);
            lua_pop(L,1); // pop table
        }

        static inline request * l_get_request(lua_State* L){
            request *req;
            lua_getglobal(L,__WEBQUEUE_TABLE); // push table t on stack
            lua_getfield(L,-1,__WEBQUEUE_REQUEST);
            req = (request*)lua_touserdata(L,-1); // value is on top
            lua_pop(L,2); // pop table and value
            return req;
        }


            int l_register_request(lua_State* L);
    }
}
#endif
